#!/bin/sh

###############################################
#     BUILDS: ncurses-ruby                    #
#       HOME: http://ncurses-ruby.berlios.de  #
#    CONTACT: bzqwerty[at]gmail[dot]com       #
###############################################

# Assumed to be public domain per our submission policy
# See the README for dependencies and other configuration information

PRGNAM=ncurses-ruby
VERSION=1.1
ARCH=${ARCH:-i486}
BUILD=${BUILD:-1}
TAG=${TAG:-_SBo}
CWD=$(pwd)
TMP=${TMP:-/tmp/SBo}
PKG=$TMP/package-$PRGNAM
OUTPUT=${OUTPUT:-/tmp}

rm -rf $PKG $TMP/$PRGNAM-$VERSION
mkdir -p $TMP $PKG $OUTPUT
cd $TMP || exit 1
tar xvf $CWD/$PRGNAM-$VERSION.tar.bz2 || exit 1
cd $PRGNAM-$VERSION || exit 1
chown -R root:root .
chmod -R a-s,u+w,go+r-w .

if [ "$ARCH" = "i486" ]; then
  SLKCFLAGS="-O2 -march=i486 -mtune=i686"
elif [ "$ARCH" = "i686" ]; then
  SLKCFLAGS="-O2 -march=i686 -mtune=i686"
fi

CFLAGS="$SLKCFLAGS" \
CXXFLAGS="$SLKCFLAGS" \
  ruby extconf.rb || exit 1

make
make install DESTDIR=$PKG

# no way to strip in Makefile
strip --strip-unneeded $PKG/usr/lib/ruby/site_ruby/1.8/i486-linux/ncurses_bin.so

mkdir -p $PKG/usr/doc/$PRGNAM-$VERSION
cp -a COPYING Changes README THANKS TODO $PKG/usr/doc/$PRGNAM-$VERSION
cat $CWD/$PRGNAM.SlackBuild > $PKG/usr/doc/$PRGNAM-$VERSION/$PRGNAM.SlackBuild

mkdir -p $PKG/install
cat $CWD/slack-desc > $PKG/install/slack-desc

cd $PKG
/sbin/makepkg -l y -c n $OUTPUT/$PRGNAM-$VERSION-$ARCH-$BUILD$TAG.tgz
